{% extends 'plugins/plugin_base.html' %}{% load i18n bootstrap_pagination humanize static sort_anchor range_filter thumbnail %}
{% block extrajs %}
  <script type="text/javascript" src="{% static "js/jquery.cookie.js" %}"></script>
  <script language="javascript">
   $(document).ready(function () {
     if ($('tr > th > a:contains("Downloads ↓")'))
     {
       $('tr > th > a:contains("Downloads ↓")').html('<img src="{% static "images/down_16.png" %}" />&darr;');
     }
     if ( $('tr > th > a:contains("Downloads ↑")') )
     {
       $('tr > th > a:contains("Downloads ↑")').html('<img src="{% static "images/down_16.png" %}" />&uarr;');
     }
     $('tr > th > a:contains("Downloads")').html('<img src="{% static "images/down_16.png" %}" />');

     if ($('tr > th > a:contains("Featured ↓")'))
     {
       $('tr > th > a:contains("Featured ↓")').html('<img src="{% static "images/star_16.png" %}" />&darr;');
     }
     if ( $('tr > th > a:contains("Featured ↑")') )
     {
       $('tr > th > a:contains("Featured ↑")').html('<img src="{% static "images/star_16.png" %}" />&uarr;');
     }
     $('tr > th > a:contains("Featured")').html('<img src="{% static "images/star_16.png" %}" />');
   });

    function toggle_desc(){
        jQuery('.plugin-description').toggle('slow', function(){
            jQuery.cookie('plugin-description-visible', jQuery('.plugin-description').is(':visible'));
        });
        if(jQuery('.plugin-description').hasClass('hidden')){
            jQuery('.plugin-description').removeClass('hidden');
        } else {
            jQuery('.plugin-description').addClass('hidden');
        }
        return false;
    }

    // Start with descriptions visible
    jQuery(function(){
        if (jQuery.cookie('plugin-description-visible') == 'true'){
            toggle_desc();
        }
    });


  </script>
{% endblock %}
{% block content %}
    <h2>{% if title %}{{title}}{% else %}{% trans "All plugins" %}{% endif %}</h2>
    {# Filtered views menu #}
    {% if object_list.count %}
    <div id="list_commands">
        <span class="num_items">{% blocktrans with records_count=page_obj.paginator.count %}{{ records_count }} records found{% endblocktrans %}</span>&nbsp;&mdash;&nbsp;
        <a class="toggle_desc" href="javascript:void(0);" onclick="return toggle_desc()">{% trans "Click to toggle descriptions." %}</a>
    </div>
    <div class="pagination">
    {#% include 'sortable_listview/sort_links.html' %#}
    </div>
    <table class="table table-striped plugins">
        <thead>
            <tr>
                <th>&nbsp;</th>
                <th>{% anchor name %}</th>
                {% if not user.is_anonymous %}<th><img title="{% trans "Approved" %}" src="{% static "images/tick_16.png" %}" alt="{% trans "Approved" %}"/></th>{% endif %}
                <th>{% anchor featured %}</th>
                <th>{% anchor downloads %}</th>
                <th>{% anchor author "Author" %}</th>
                <th>{% anchor latest_version_date "Latest Plugin Version" %}</th>
                <th>{% anchor created_on "Created on" %}</th>
                <th>{% anchor average_vote "Stars (votes)" %}</th>
                <th>{% trans "Stable" %}</th>
                <th>{% trans "Exp." %}</th>
                {% if user.is_authenticated %}<th colspan="2">{% trans "Manage" %}</th>{% endif %}
            </tr>
        </thead>
        <tbody>
            {% for object in object_list %}
            <tr class="pmain {% if object.deprecated %} error deprecated{% endif %}" id="pmain{{object.pk}}">
                <td><a title="{% if object.deprecated %} [DEPRECATED] {% endif %}{% trans "Click here for plugin details" %}" href="{% url "plugin_detail" object.package_name %}">
                {% if object.icon and object.icon.file %}
                {% thumbnail object.icon "24x24" format="PNG" as im %}
                    <img class="plugin-icon" alt="{% trans "Plugin icon" %}" src="{{ im.url }}" width="{{ im.x }}" height="{{ im.y }}" />
                {% endthumbnail %}
                {% else %}
                    <img height="32" width="32" class="plugin-icon" src="{% static "images/qgis-icon-32x32.png" %}" alt="{% trans "Plugin icon" %}" />
                {% endif %}
                </a></td>
                <td><a title="{% if object.deprecated %} [DEPRECATED] {% endif %}{% trans "Click here for plugin details" %}"  href="{% url "plugin_detail" object.package_name %}">{{ object.name }}</a></td>
                {% if not user.is_anonymous %}<td>{% if object.approved %}<img src="{% static "images/tick_16.png" %}" />{% else %}&mdash;{% endif %}</td>{% endif %}
                <td>{% if object.featured%}<img src="{% static "images/tick_16.png" %}" />{% else %}&mdash;{% endif %}</td>
                <td>{{ object.downloads }}</td>
                <td><a title="{% trans "See all plugins by"%} {{ object.author }}" href="{% url "author_plugins" object.author %}">{{ object.author }}</a></td>
                <td>{{ object.latest_version_date|naturalday }}</td>
                <td>{{ object.created_on|naturalday }}</td>
                <td><div><div class="star-ratings"><span style="width:{% widthratio object.average_vote 5 100 %}%" class="rating"></span></div> ({{ object.rating_votes }})</div></td>
                <td>{% if object.stable %}<a href="{% url "version_download" object.package_name object.stable.version %}" title="{% trans "Download the stable version" %}" >{{ object.stable.version }}</a>{% else %}&mdash;{% endif %}</td>
                <td>{% if object.experimental %}<a href="{% url "version_download" object.package_name object.experimental.version %}" title="{% trans "Download the experimental version" %}" >{{ object.experimental.version }}</a>{% else %}&mdash;{% endif %}</td>
                {% if user.is_authenticated %}{% if user in object.editors or user.is_staff %}<td><a class="btn btn-primary btn-mini" href="{% url "plugin_update" object.package_name %}"><i class="icon-pencil icon-white" title="{% trans "Edit" %}"></i></a>
                <a class="btn btn-danger btn-mini"  class="delete" href="{% url "plugin_delete" object.package_name %}"><i class="icon-remove-sign icon-white" title="{% trans "Delete" %}"></i></a>{% else %}{% endif %}</td>{% endif %}

            </tr>

            <tr id="pdesc{{object.pk}}" class="hidden plugin-description {% cycle "even" "odd" %}" title="{% trans "Click to hide" %}"><td>&nbsp;</td><td colspan="{% if user.is_authenticated %}9{% else %}8{% endif %}">{{ object.description }}</td></tr>

            {% endfor %}
        </tbody>
    </table>
    <div class="pagination">
    {% include 'sortable_listview/pagination.html' %}
    </div>
    <div class="alert">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        {% trans "Deprecated plugins are printed in red." %}
    </div>
    {% else %}
    {% block plugins_message %}
    <div class="alert">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        {% trans "This list is empty!" %}
    </div>
    {% endblock %}
    {% endif %}
    <script type="text/javascript">
        jQuery('.popover').popover();
    </script>
{% endblock %}
